<?php
if( !defined('IN') ) die('bad request');
include_once( AROOT . 'controller'.DS.'app.class.php' );

class goodsController extends appController
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$data['title'] = $data['top_title'] = 'SCUT SHOP';
		$data['js'] = array('jquery-1.3.1.js',
							'jquery.cookie.js',
							'nav.js',
							'changeSkin.js',
							'jquery.jqzoom.js',
							'use_jqzoom.js',
							'jquery.thickbox.js',
							'jquery.livequery.js',
							'switchImg.js',
							'tab.js',
							'switchColor.js',
							'sizeAndprice.js',
							'star.js',
							'finish.js' );
		$data['css'] = array('main.css',
							 'detail.css',
							 'skin/skin_0.css',
							 'thickbox.css');
		render( $data );
	}
	
	function show()
	{
		$data['id'] = $id = v('id');
		$data['goods'] = selectone('id', $id, 'Good');
		$data['gImage'] = select('id', $id, 'gImage');
		
		$data['title'] = $data['top_title'] = 'SCUT SHOP | '.$data['goods']['gName'];
		
		$data['js'] = array('jquery-1.3.1.js',
							'jquery.cookie.js',
							'nav.js',
							'changeSkin.js',
							'jquery.jqzoom.js',
							'use_jqzoom.js',
							'jquery.thickbox.js',
							'jquery.livequery.js',
							'switchImg.js',
							'tab.js',
							'switchColor.js',
							'sizeAndprice.js',
							'star.js',
							'finish.js' );
		$data['css'] = array('main.css',
							 'detail.css',
							 'skin/skin_0.css',
							 'thickbox.css');
		render( $data );
	}
	
	function getGoodInfo($id)
	{
	}
	
	function createDB()
	{
		echo runSql("create table Good (
			id int primary key auto_increment,
			gName varchar(50) binary not null,
			description text binary,
			price varchar(50) binary
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
		showError();
	}
	
	function createDBforGoodsImage()
	{
		echo runSql("create table gImage (
			gid int primary key auto_increment,
			id int not null,
			url text binary,
			FOREIGN KEY(id) REFERENCES Good on delete cascade
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
		showError();
	}
	
	function addGoods($gName, $description, $price)
	{
		runSql( "insert into Good (gName,description,price) values ('$gName','$description','$price')");
		showError();
	}
	
	function addGImage($id, $url)
	{
		runSql( "insert into gImage (id,url) values ('$id','$url')");
		showError();
	}
	
	function addTestData()
	{
		$this->addGoods("超短裙", "没有什么特点，就是超短~ 难以置信的短啊","只要 998~");
		$this->addGoods("爱疯88", "什么都可以，就是不能打电话！","只要 999美元~");
		$this->addGoods("联想 内裤", "穿上它，你就有了联想的能力~","只要 111~");
	}
	
	function addTestImage()
	{
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/6b49af30076f2bfe5cf46c470def_1200_1200.jpg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/b9f6614002efe4e854c0969c5300_800_800.jpg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/b077025229fb51e831e64bb1d1e3_800_800.jpg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/27d5e79c06a3b5ed47e736b4e694_800_830.jpeg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/60c00dc616617cc79e4ed998fc18_716_542.jpeg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/20110412160734_euncm.jpg");
	//	$this->addGImage(1,"http://scutshop-sdcard.stor.sinaapp.com/DAZZLE-202S20311-2.jpg");
		
	//	$this->addGImage(2,"http://scutshop-sdcard.stor.sinaapp.com/002564ab85ff11bcb3592a.jpg");
	//	$this->addGImage(2,"http://scutshop-sdcard.stor.sinaapp.com/201203050933218579.jpg");
		
	//	$this->addGImage(3,"http://scutshop-sdcard.stor.sinaapp.com/c09df03cjw1e3y7u3l1t0j20cs09ywfn.jpg");
	}
}